package com.eppear.jpfm.framework.util;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName SequnceUtil
 * @Description
 *         序列类
 * @author JianFeng Zhang(张建锋)
 * @date   2018-01-28 下午1:00:24
 *
 */
@Component
public class SequnceUtil {

	private static Logger log = LoggerFactory.getLogger(SequnceUtil.class);
	
	@Autowired
	private SqlSession sqlSession;
	private static SequnceUtil sequnceUtil;
	
	@PostConstruct
	public void init(){
		sequnceUtil = this;
		sequnceUtil.sqlSession = this.sqlSession;
	}
	
	/**
	 *  获取流水号
	 *  返回4位数,按天重置
	 * @return
	 */
	public static String getFlowNo(){
				
		String sqId= "sysSequence.getFlowNo";
    	Map<String,Object> rMap = new HashMap<String,Object>();
    	rMap.put("key", "FLOW_NO");
    	rMap.put("dayRest", "Y");
    	rMap.put("len", 4);
    	
    	sequnceUtil.sqlSession.selectOne(sqId,rMap);
    	log.debug("序列结果为rMap:{}",rMap);
    	
    	return (String)rMap.get("seqValue");
	}
}
